/**
 * 题目链接：
 * 完成时间：2025/11/12 10:56
 * 简要思路：
 */
#include <bits/stdc++.h>
#define range(i, b, e) for (auto i(b); i != (e); i++)
#define rep(i, b, e) for (auto i(b); i <= (e); i++)
#define req(i, b, e) for (auto i(b); i >= (e); i--)
using namespace std;
typedef long long LL;
typedef pair<int, int> Pii;

const int N = 1e5;
int n;
string st[N+5];
int cnt[2];

int sum(int s) {
	int l = /*1 << __lg(s-1)*/s/2;
	return s <= 1 ? 0 : s + sum(l) + sum(s-l);
}

int main() {
	freopen("id.in", "r", stdin);
	freopen("id.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	for (int i = 1, x; i <= n; i++) cin >> x, cnt[x]++;
	cout << sum(cnt[0]) + sum(cnt[1]);
	return 0;
}
